﻿using IntelligentAgriculture.Contracts.Dto.Input.EarTagInput;
using IntelligentAgriculture.Contracts.Dto.Input.RidgepInput;
using IntelligentAgriculture.Contracts.Dto.Output.EarTagOutput;
using IntelligentAgriculture.Contracts.Dto.Output.PageOutput;
using IntelligentAgriculture.Contracts.Dto.Output.RidgepOutPut;
using IntelligentAgriculture.Contracts.Interface.Iridgepletype;
using IntelligentAgriculture.Domain.Entity;
using IntelligentAgriculture.Domain.Interface.IEarTagReposiotry;
using IntelligentAgriculture.WebAPI.Application.Command.EarTageCommand;
using IntelligentAgriculture.WebAPI.Application.Command.ManageCommand;
using IntelligentAgriculture.WebAPI.Application.Command.RidgepCommand;
using IntelligentAgriculture.WebAPI.Application.Command.RidgepCpoamd;
using IntelligentAgriculture.WebAPI.Application.Command.StartCommand;
using IntelligentAgriculture.WebAPI.Controllers.RidgepoleController;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using NPOI.XSSF.Streaming.Values;
using NPOI.XWPF.UserModel;

namespace IntelligentAgriculture.WebAPI.Controllers.EarTagesController
{
    /// <summary>
    /// 耳标管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class EarTageController : ControllerBase
    {
        private readonly IEarTagReposiotry iearTagReposiotry;
        private readonly TokenService _tokenService;
        private readonly ILogger<RidgepolesController> _logger;
        private readonly IMediator _mediator;
        public EarTageController(IEarTagReposiotry iearTagReposiotry, TokenService tokenService, ILogger<RidgepolesController> logger, IMediator mediator)
        {
            this.iearTagReposiotry = iearTagReposiotry;
            _tokenService = tokenService;
            _logger = logger;
            _mediator = mediator;
        }



        /// <summary>
        /// 耳标显示、分页和查询功能
        /// </summary>
        /// <param name="input">输入参数，用于指定查询条件</param>
        /// <returns>返回一个包含查询结果的异步任务结果</returns>
        [HttpGet]
        public async Task<Results<PagesOutput<EarTageShowsOutPut>>> GetShow([FromQuery] EarTageShowInput? input)
        {
            try
            {
                var list = new EarTageShowCommand(input);
                return await _mediator.Send(list);
            }
            catch (Exception)
            {

                throw;
            }
        }



        /// <summary>
        /// 耳标添加功能
        /// </summary>
        /// <param name="coomand">添加实体</param>
        /// <returns>返回受影响行数</returns>
        [HttpPost]
        public async Task<Results<int>> Addeartage(EarTageAddCommand coomand)
        {
            try
            {
                return await _mediator.Send(coomand);

            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 耳标单个逻辑删除处理删除耳标命令的 HTTP DELETE请求。
        /// </summary>
        /// <param name="command">包含要删除的耳标信息的命令对象</param>
        /// <returns>一个表示操作结果的异步任务，返回删除操作的结果</returns>
        [HttpDelete]
        public async Task<Results<int>> Delete(EarTageDelCommand command)
        {
            try
            {
                return await _mediator.Send(command);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 耳标批量逻辑删除 HTTP DELETE 方法发送的批量删除命令
        /// </summary>
        /// <param name="command">包含要执行批量删除操作的命令对象</param>
        /// <returns>一个表示操作结果的异步任务，返回批量删除操作的结果</returns>
        [HttpPut]
        public async Task<Results<int>> DeleteRange(EarTageDelRangeCommand command)
        {
            try
            {
                return await _mediator.Send(command);
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 羊只品种
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public object ShowEarTageBreed()
        {
            List<object> list = new List<object>();
            foreach (EarTagBreedsDTO item in Enum.GetValues(typeof(EarTagBreedsDTO)))
            {
                list.Add(new
                {
                    name = item.ToString(),
                    Value = item
                });
            }
            return Results<object>.DataResult(list);
        }


        /// <summary>
        /// 反填功能
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Results<EarTageShowsOutPut>>GetFind(int id)
        {
            try
            {
                var command = new EarTageFindCommand(id);
                var roles = await _mediator.Send(command);
                return roles;
            }
            catch (Exception)
            {

                throw;
            }
        }




        /// <summary>
        /// 修改耳标表
        /// </summary>
        /// <param name="command">耳标实体</param>
        /// <returns>受影响的行数</returns>
        [HttpPost]
        public async Task<Results<int>> UpdateStart(EarTageUpdateCommand command)
        {
            try
            {
                _logger.LogInformation("这是修改耳标表");
                return await _mediator.Send(command);
            }
            catch (Exception ex)
            {
                _logger.LogError("这是修改耳标表发生异常" + ex.Message);
                throw;
            }

        }
        /// <summary>
        /// 显示未使用的耳标
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<Results<IQueryable<Eartag>>> ShowStateEartag()
        {
            try
            {
                var command = new ShowStateEartagCommand();

				return await _mediator.Send(command);
            }
            catch (Exception)
            {

                throw;
            }
        }



    }

}
